package com.zk.cq.config;/**
 * Created by 15911 on 2019/6/30.
 */

import com.alibaba.fastjson.JSONObject;
import com.zk.cq.handler.DispatcherHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.InvocationTargetException;

/**
 * @ClassName RobotConfig
 * @Descripyion 读取properties
 * @Author zhangkuan
 * @Date 2019/6/30 13:47
 **/
@Slf4j
@Configuration
@RestController
@RequestMapping("/")
public class RobotConfig {

    public static boolean rootPathLog = true;
//    public static Long robotQQNo;

    @Value("${zk.rootPathLog:true}")
    public void setRootPathLog(boolean rootPathLog) {
        this.rootPathLog = rootPathLog;
    }

    @PostMapping("/")
    public Object receive(HttpServletRequest request, @RequestBody JSONObject req) throws InvocationTargetException, IllegalAccessException {
        if (rootPathLog){
            log.info("接收到来自【" + request.getHeader("X-Self-ID") + "】机器人的事件");
        }
        return DispatcherHandler.handler(req);
    }

//    @PostConstruct
//    public static void init(){
//        robotQQNo = JSON.parseObject(Send.getLoginInfo()).getLong("user_id");
//    }
}
